package cn.chenmanman.system.exception;

import cn.chenmanman.common.result.Result;
import cn.chenmanman.system.exception.extend.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GloableExceptionHandler {

    /**
     * 全局异常处理
     * */
    @ExceptionHandler(Exception.class)
    public Result error(Exception ex){
        log.error("捕获到错误:", ex);
        return Result.fail().message("系统错误!");
    }

    @ExceptionHandler(BizException.class)
    public Result error1(BizException bizException){
        return Result.fail().message(bizException.getMsg()).code(bizException.getCode());
    }
}
